/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-26
 * Time: 14:06
 */
//懒汉模式
class SingletonLazy {
      volatile private static SingletonLazy instance = null;

    public static SingletonLazy getInstance() {
        if (instance == null) {
            synchronized (SingletonLazy.class) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }

            }

        }
            return instance;
    }
    private  SingletonLazy(){

    }
}
public class ThreadDemo2 {
    public static void main(String[] args) {
            SingletonLazy s1=SingletonLazy.getInstance();
            SingletonLazy s2=SingletonLazy.getInstance();
        System.out.println(s1==s2);//true

    }
}
